<template>
  <div class="sessionCon flexC">
    <div class="aiCon">
      <span class="ai flexC">
        <img :src="`${imgurl}ai.png`" />
      </span>
      <span class="tit-1 flexC">
        你好，我是<img :src="`${imgurl}slogen.png`" />
      </span>
      <span class="tit-2 flexC" v-if="base.isMobile">
        WIRE AI是一个全方位的智能服务平台<br />
        致力于为您提供有关丝网行业的深度信息和专业见解<br />
        我们涵盖五大核心领域：<br />
        丝网知识库、丝网产品展示<br />
        丝网企业名录、丝网机器设备录、丝网材料数据库
      </span>
      <span class="tit-2 flexC" v-else>
        WIRE
        AI是一个全方位的智能服务平台，致力于为您提供有关丝网行业的深度信息和专业见解。<br />我们涵盖五大核心领域：丝网知识库、丝网产品展示、丝网企业名录、丝网机器设备录、丝网材料数据库。
      </span>
    </div>

    <div class="aititle" :style="base.isCommand?'bottom:405px':''">
      <div class="aititleleft">
        <img :src="`${imgurl}aititle.png`" alt="" />
        <img :src="`${imgurl}aiboxtitle_jt.png`" class="jt" alt="" @click="shwoAibox">
      </div>
      <div class="aititleright">
        <div class="hyh" @click="hyhFun">
          <img
            :src="`${imgurl}hyh.png`"
            alt=""
            :class="hyhStatus ? 'imgRountion' : ''"
          />
          换一换
        </div>
        <div class="morehyh" @click="shwoAibox">
          更多 <img :src="`${imgurl}hyhmore.png`" alt="" />
        </div>
      </div>
    </div>

    <div
      :class="[{ active: base.isShowLeft }, 'presetsList']"
      id="presetsList"
      v-if="!base.isMobile"
      :style="
        base.guideIndex == 1
          ? `position:fixed; width:780px; z-index:999; `
          : base.isCommand == true
          ? 'bottom:240px'
          : ''
      "
    >
      <div
        :class="[{ disable: base.guideIndex != 0 }, 'presetsItem']"
        v-for="item in list"
        :key="item.id"
        @click="base.guideIndex == 0 ? createTitle(item) : ''"
      >
        <span :class="`${item.class} title show`">
          <img :src="item.iconpath" alt="" v-if="item.type == 1" />
          <img :src="baseurl + item.iconpath" alt="" v-else />
          {{ item.title }}
        </span>
        <span class="desciption show">
          {{ item.command }}
        </span>
      </div>
    </div>
    <div
      class="presetsList"
      id="presetsList"
      v-else
      :style="
        base.guideIndex == 1
          ? `position:fixed; width:100%; z-index:999;bottom:100px;`
          : ''
      "
    >
      <div
        :class="[{ disable: base.guideIndex != 0 }, 'presetsItem']"
        v-for="item in list"
        :key="item.id"
        @click="base.guideIndex == 0 ? createTitle(item) : ''"
      >
        <span :class="`${item.class} title show`">
          {{ item.title }}
        </span>
        <span class="desciption show">
          {{ item.command }}
        </span>
      </div>
    </div>

    <!-- 弹窗 -->
  </div>

</template>

<script setup lang='ts'>
import { useSystemStore } from "@/store/modules/system";
import { debounces } from "../../utils/base.ts";
import { basename } from "path-browserify";
const aiboxShow = ref(false);
const api = inject("$base", null as any);
const baseurl = inject("$baseurl", null as any);

const $_ = inject("$_", null as any);
const base = useSystemStore();
const imgurl = import.meta.env.VITE_APP_TITLE + "/assets/images/";
const presetsList = ref<any>([
  {
    id: 1,
    class: "c1",
    title: "智能咨询",
    command: "产品百科（介绍丝网行业的所有产品）",
    iconpath: imgurl + "c1.png",
    type: 1,
  },
  {
    id: 2,
    class: "c2",
    title: "安全规范",
    command: "声屏障国家规范",
    iconpath: imgurl + "c2.png",
    type: 1,
  },
  {
    id: 3,
    class: "c3",
    title: "服务推荐",
    command: "声屏障有哪些品牌推荐",
    iconpath: imgurl + "c3.png",
    type: 1,
  },
  {
    id: 4,
    class: "c4",
    title: "技术解析",
    command: "企业百科（介绍丝网制造领域的优秀企业）",
    iconpath: imgurl + "c4.png",
    type: 1,
  },
]);
const presetsList2 = ref<any>([
  {
    id: 1,
    class: "c1",
    title: "智能咨询",
    desciption: "产品百科（介绍丝网行业的所有产品）",
    iconpath: imgurl + "c1.png",
    type: 1,
  },
  {
    id: 4,
    class: "c4",
    title: "技术解析",
    desciption: "企业百科（介绍丝网制造领域的优秀企业）",
    iconpath: imgurl + "c4.png",
    type: 1,
  },
  {
    id: 2,
    class: "c2",
    title: "安全规范",
    desciption: "声屏障国家规范",
    iconpath: imgurl + "c2.png",
    type: 1,
  },
  {
    id: 3,
    class: "c3",
    title: "服务推荐",
    desciption: "声屏障有哪些品牌推荐",
    iconpath: imgurl + "c3.png",
    type: 1,
  },
]);
const list = ref<any>([]);
const emit = defineEmits(["createTitle"]);
let hyhStatus = ref(false);
function shwoAibox() {
  base.aiboxShow = true;
}

function hyhFun() {
  console.log("33333333333333333333333");

  hyhStatus.value = true;
  setTimeout(() => {
    hyhStatus.value = false;
  }, 1000);
  page.value++;
  api.commandindex({ page: page.value }).then((res) => {
    list.value = res.data.list;
    if (page.value == res.data.pagecount) {
      page.value = 0;
    }
  });
}
function createTitle(item) {
  console.log(base.isCreatLoad);

  if (base.isCreatLoad == true) {
    return;
  }
  console.log(item.type);

  if (item.type == 1) {
    console.log("2222222222222222");
    base.curCommand = "";
    base.isCommand = false;
    base.isCreatLoad = true;
    base.isNewSess = true;
    base.inSessionId = 0;
    base.listpage = 1;
    console.log(base.inSessionId, "base.inSessionId");
    emit("createTitle", item.command);
  } else {
    console.log("4444444444444444444");
    base.curCommand = item;
    base.isCommand = true;
  }
}
watch(base.guideIndex, (newValue, oldValue) => {
  console.log("watch 已触发", newValue);
});
const page = ref(0);

onMounted(() => {
  if (base.isMobile) {
    list.value = presetsList2.value;
  } else {
    list.value = presetsList.value;
  }
  const divElement = document.getElementById("presetsList");
  if (divElement) {
    const rect = divElement.getBoundingClientRect();
    base.guideLeft = rect.left;
    base.guideTop = rect.top;
  }
  window.addEventListener("resize", () => {
    const divElement = document.getElementById("presetsList");
    if (divElement) {
      const rect = divElement.getBoundingClientRect();
      base.guideLeft = rect.left;
    }
  });
});
</script>
<style lang="scss" scoped>
.aititleleft{
  height:19px;
  overflow: hidden;
  .jt{
    margin-left: 5px;
    cursor: pointer;
  }
}
.list_mes{
  width: 24px;
  height: 21px;
  overflow: hidden;
  img{
    width: 24px;
  height: 21px;
  }
}
@keyframes rotation {
  from {
    -webkit-transform: rotate(0deg);
    transform: rotate(0deg);
  }

  to {
    -webkit-transform: rotate(-180deg);
    transform: rotate(-180deg);
  }
}
.aititle {
  display: flex;
  width: 780px;
  clear: both;
  justify-content: space-between;
  align-items: center;
  padding: 0 10px;
  left: calc((100% - 780px) / 2);
  position: absolute;
  bottom: 351px;
  transition: all 0.8s;

  .aititleright {
    display: flex;
    align-items: center;
    color: #3a6abd;
    font-size: 14px;
    .hyh {
      display: flex;
      align-items: center;
      padding-right: 5px;
      margin-right: 5px;
      position: relative;
      cursor: pointer;
      img {
        margin-right: 5px;
      }
      .imgRountion {
        animation: rotation 0.5s linear;
      }
    }
    .hyh::after {
      width: 1px;
      height: 14px;
      content: "";
      position: absolute;
      right: 0;
      background: #3a6abd;
    }
    .morehyh {
      cursor: pointer;
    }
  }
}

.sessionCon {
  width: 780px;
  margin: 0 auto;
  position: relative;
  height: 100vh;
  padding-bottom: 350px;
  overflow: hidden;
  flex-wrap: wrap;
  align-content: center;
  // background:#000;
  .ai {
    height: 100px;
    width: 100%;
    img {
      width: 75px;
      height: 75px;
    }
  }
  .tit-1 {
    font-size: 26px;
    color: #0189f6;
    height: 40px;
    font-family: "siyuanM";
    img {
      height: 20px;
      margin-left: 5px;
      margin-top: 5px;
    }
  }
  .tit-2 {
    font-size: 14px;
    color: #5f7298;
    text-align: center;
    line-height: 26px;
    font-family: "siyuanN";
    margin-top: 10px;
  }
  .presetsList {
    width: 780px;
    display: grid;
    padding: 5px;
    grid-template-columns: repeat(2, 1fr);
    position: fixed;
    bottom: 190px;
    left: calc((100% - 280px) / 2 + 280px);
    margin-left: -390px;
    padding-bottom: 5px;
    transition: all 0.8s;
    &.active {
      left: 50%;
    }
    .presetsItem {
      background: #f7fafe;
      border-radius: 5px;
      margin: 5px;
      padding: 5px 28px;
      display: flex;
      justify-content: center;
      align-items: left;
      flex-direction: column;
      min-height: 65px;
      border: solid 1px #f7fafe;
      cursor: pointer;
      transition: all 0.6s;
      font-family: "siyuanR";
      .disable {
        cursor: default;
      }
      .title {
        color: #1b56b6;
        font-size: 18px;
        line-height: 30px;
        display: flex;
        align-items: center;
        img {
          width: 23px;
          margin-right: 5px;
        }
      }
      .desciption {
        font-size: 14px;
        color: rgba(95, 114, 152, 0.7);
        line-height: 20px;

        display: -webkit-box;
        -webkit-line-clamp: 1;
        -webkit-box-orient: vertical;
        overflow: hidden;
        text-overflow: ellipsis;
      }
      &:hover:not(.disable) {
        background: #fff;
        border: solid 0.75px #bcd1fb;
        transform: translateY(-5px);
        box-shadow: -10px 15px 15px -5px rgba(166, 182, 229, 0.3);
        .desciption {
          color: #1b56b6;
        }
      }
      // box-shadow:0 3px 7px rgba(166,182,229,.2);
    }
  }
}
@media screen and (max-width: 1080px) {
  .sessionCon {
    .presetsList {
      width: calc(100% - 290px);
      margin-left: 0;
      left: 285px;
      &.active {
        left: 0;
        width: 100%;
      }
    }
  }
  .aititle {
    width: 90%;
    left: auto;
    bottom: 381px;
  }
  .close_box {
    top: calc((100vh - 658px) / 2 - 10px);
    right: 20px;
  }
}
@media screen and (max-width: 768px) {
  .sessionCon {
    width: 100%;
    padding: 0 20px 380px 20px;
    .ai {
      height: 60px;
      img {
        width: 50px;
        height: 50px;
      }
    }
    .tit-2 {
      line-height: 20px;
      font-size: 14px;
      white-space: nowrap;
    }
    .presetsList {
      // grid-template-columns: repeat(1, 1fr);
      // bottom:170px;
      width: 100%;
      bottom: 120px;
      left: 0;
      padding: 10px 15px;
      .presetsItem {
        height: 90px;
        padding: 10px 15px;
        min-height: 30px;
        .title {
          line-height: 30px;
        }
        .desciption {
          line-height: 20px;
          font-size: 12px;
        }
      }
    }
  }
}
</style>